package com.example.rtsp2.exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 杜科璇
 * @Description: 全局异常处理
 * @Date: 2025/9/8 9:10
 * @Version: 1.0
 */

@ControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    public ResponseEntity<Map<String, String>> handleException(Exception e) {
        logger.error("捕获到未处理的异常", e);

        Map<String, String> response = new HashMap<>();
        response.put("error", "内部服务器错误");
        response.put("message", e.getMessage());

        return ResponseEntity.status(500).body(response);
    }
}